import time

from common.Tools import Tools
from page.general import General


class PVPPage(General, metaclass=Tools):
    PVP = 'pvp.jpg'
    WUXIN_RITUAL = 'wuxin_ritual.jpg'
    WUXIN_RITUAL_ALL_TEAMS = 'wuxin_ritual_all_teams.jpg'
    SECOND_ROUND = 'second_round.jpg'
    THIRD_ROUND = 'third_round.jpg'
    RECEIVE = 'receive.jpg'

    def click_pvp(self):
        return self.click_match_xy(self.PVP)

    def click_wuxin_ritual(self):
        return self.click_match_xy(self.WUXIN_RITUAL)

    def click_wuxin_ritual_all_teams(self):
        return self.click_match_xy(self.WUXIN_RITUAL_ALL_TEAMS)

    def click_second_round(self):
        return self.click_match_xy(self.SECOND_ROUND)

    def click_third_round(self):
        return self.click_match_xy(self.THIRD_ROUND)

    def click_receive(self):
        return self.click_match_xy(self.RECEIVE)

    def pvp_process(self):
        while not self.click_receive():
            time.sleep(2)
        self.click_close()
        while not self.get_match_xy('pvp_clear.jpg'):
            self.click_challenge(0)
            while not self.get_match_xy(self.COMBAT_START):
                time.sleep(2)
            self.click_unselected()
            self.click_close()
            self.click_second_round()
            self.click_third_round()
            self.click_combat_start()
            while not self.get_match_xy(self.NEXT,0.75):
                time.sleep(2)
            while not self.get_match_xy(self.CHALLENGE):
                self.click_next()
